<?php

/**
 * Reports actions.
 *
 * @package    Amawal Invest
 * @subpackage Reports
 * @author     Ameen Shoman<amin.shoman@gmail.com>
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ReportsActions extends sfActions
{
	/**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */

	public function preExecute()
	{
		$title = sfInflector::underscore($this->getActionName());
		$arr = explode( '_' , $title );
		$arr = array_map( 'ucfirst' , $arr );
		$this->title = implode(' ' , $arr);
	}
	public function executeIndex(sfWebRequest $request)
	{
		//$this->redirect('@homepage',301);
	}

	public function executeEmployeeChartReport(sfWebRequest $request){


		require_once(dirname(__FILE__).'/../lib/EmployeeChartReportForm.class.php');

		$this->setTemplate('form');
		//$this->title = "Employee Information";
		$this->form = new EmployeeChartReportForm();

		if($request->isMethod('post')){
			$this->processForm($this->form);
		}

	}
	public function executeEmployeeInformationReport(sfWebRequest $request)
	{

		require_once(dirname(__FILE__).'/../lib/EmployeeInformationReportForm.class.php');

		$this->setTemplate('form');
		//$this->title = "Employee Information";
		$this->form = new EmployeeInformationReportForm();

		if($request->isMethod('post')){
			$this->processForm($this->form);
		}



	}
	public function executeEmployeeLeavesReport(sfWebRequest $request)
	{
		require_once(dirname(__FILE__).'/../lib/EmployeeLeavesReportForm.class.php');
		$this->setTemplate('form');
		$this->form = new EmployeeLeavesReportForm();

		if($request->isMethod('post')){
			$this->processForm($this->form);
		}



	}
	public function executeUnclosedTransactionReport(sfWebRequest $request)
	{
		require_once(dirname(__FILE__).'/../lib/UnclosedTransactionForm.class.php');
		$this->setTemplate('form');
		$this->form = new UnclosedTransactionForm();

		if($request->isMethod('post')){
			$this->processForm($this->form);
		}



	}
	public function executeEmployeeLeavesComparisonsReport(sfWebRequest $request)
	{
		require_once(dirname(__FILE__).'/../lib/EmployeeLeavesComparisons.class.php');
		$this->setTemplate('form');
		$this->form = new EmployeeLeavesComparisons();

		if($request->isMethod('post')){
			$this->processForm($this->form);
		}



	}
	public function executeEmployeeLeavesPercentageReport(sfWebRequest $request)
	{
		require_once(dirname(__FILE__).'/../lib/EmployeeLeavesPercentage.class.php');
		$this->setTemplate('form');
		$this->form = new EmployeeLeavesPercentage();

		if($request->isMethod('post')){
			$this->processForm($this->form);
		}



	}

	public function processForm(BaseReportForm $form)
	{
		/* @var sfWebRequest $request*/
		$request = $this->getRequest();
		$form->bind($request->getParameter($form->getName()));
		if($form->isValid()){
			//print_r($form->getValue('created_at'));exit;

			$this->criteria = $criteria = $form->getCriteria();
			//echo "<pre>";print_r($criteria);exit;
			$model = $form->getModelName();
			//echo "<pre>";print_r($model);exit;
			$this->setTemplate('view');
			$this->fields = $form->getDisplayFields();
			$this->form_template = $form->getTemplate();
			if($criteria->hasSelectClause()){
				$this->data = call_user_func_array($model.'Peer::doSelectStmt',array($criteria));
			}elseif(!constant($model.'Peer::IS_I18N')){
				$this->data = call_user_func_array($model.'Peer::doSelect',array($criteria));
			}else{
				$this->data = call_user_func_array($model.'Peer::doSelectWithI18n',array($criteria));
			}

		}

	}
}
